<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>添加素材</title>
<link href="css/tscss.css" rel="stylesheet" type="text/css" /> 
<link href="css/smsstyle.css" rel="stylesheet" type="text/css" />
<link href="css/bmasdo2.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="js/commons.js"></script>
<style type="text/css">
	.operation{
		cursor:pointer;
		color: blue;
	}
	.operation:hover{
		color: red;
	}
</style>

<%
	String f_vc_parentid = request.getParameter("f_vc_parentid");
	if(f_vc_parentid == null || "null".equals(f_vc_parentid)){
		f_vc_parentid = "0";
	}
	String insertOrUpdate = request.getParameter("insertOrUpdate");//判断是新增还是修改
	String f_vc_id = request.getParameter("f_vc_id");//频道id
	if(f_vc_id == null || "null".equals(f_vc_id)){
		f_vc_id = "0";
	}
	String f_vc_customid = request.getParameter("f_vc_customid");
	if(f_vc_customid == null || "null".equals(f_vc_customid)){
		f_vc_customid = "0";
	}
	//其实继续用上面的两个参数也可以，再加个参数表示插播也行
	String cbf_vc_id = request.getParameter("cbf_vc_id");
	String cbf_vc_parentid = request.getParameter("cbf_vc_parentid");
	if(cbf_vc_id == null || "null".equals(cbf_vc_id)){
		cbf_vc_id = "0";
	}
	if(cbf_vc_parentid == null || "null".equals(cbf_vc_parentid)){
		cbf_vc_parentid = "0";
	}
	String processType = request.getParameter("processType");
	
	String turnid = request.getParameter("turnid");//频道id
	String turnpid = request.getParameter("turnpid");//频道id
	String turncid = request.getParameter("turncid");//频道id
	String []nonceObj=ConstantUtils.getNonceObject();
%>
</head>
<script language="javascript">
    var offAirTime_='';
	var f_vc_customid = '<%=f_vc_customid%>';
 	var f_vc_parentid = '<%=f_vc_parentid%>';//频道父id
 	var f_vc_id = '<%=f_vc_id%>';
 	var cbf_vc_parentid = '<%=cbf_vc_parentid%>';
 	var cbf_vc_id = '<%=cbf_vc_id%>';
 	var turnid="<%=turnid%>";
 	var turnpid="<%=turnpid%>";
 	var turncid="<%=turncid%>";
 	var processType = '<%=processType%>';//动作类型，例如：插播新增 interCutInsert 插播修改 interCutUpdate
	var f_cc_id = 0;
	var f_vcm_type = 0;
 	var insertOrUpdate = '<%=insertOrUpdate%>';
 	var timeSelect = '';//插播时选中的时间 用这个时间+素材总时长，就是插播内容的停播时间 timeSelect + sumTime
 	
 	var fvcid = 0;//`f_vc_id` int(10) NOT NULL AUTO_INCREMENT COMMENT '虚拟频道唯一id',
 	/*
 		统一保存按钮
 		
 	*/
	function save(){
		var canSave = true;
		var _f_vc_airTime = document.forms[0].f_vc_airTime.value;//开播时间
		if (document.forms[0].f_vc_name.value == ""){
			alert("节目名称不能为空");
			return;
		}
		if (document.forms[0].f_vc_airTime.value == ""){
			alert("开始时间不能为空");	
			return;
		}
		if(!canSave){
			alert("转播节目时长不能为0或空");
			return;
		}
		
		if(cbf_vc_parentid!='0'){//代表插播，插播的时候结束时间是素材的总时间+当前插播时间
			timeSelect = $("#f_vc_airTime").val();//
			$("#f_vc_customid").val(f_vc_customid);
			$("#f_vc_parentid").val(cbf_vc_parentid);
			var timeSelects = timeSelect.split(":");
			var sum = getS(timeSelects)+sumTime;
			$("#f_vc_offAirTime").val(getHMS(sum));
			// sumTime 
		}
		var _f_vc_offAirTime = $("#f_vc_offAirTime").val();//停播时间
		canSave = validateAirAndOffAir(_f_vc_airTime,_f_vc_offAirTime);//验证开播时间和停播时间是否有效
		console.log('保存时canSave:'+canSave);
		//if(!canSave){
			//alert("请检查开播时间和停播时间");
			//return;
		//}
		
		
	}
 	
 	function saveData(){
 		var requesturl="../../virtual_channel/insert_vchannel_material.do";
		if(insertOrUpdate == "update" || processType== 'interCutUpdate'){
			requesturl="../../virtual_channel/update_channel_material.do";
		}
		$.ajax({
			url: requesturl,
			data: $("#virtual_channel_form").serialize(),
			dataType: "json",
			type: "post",
			success: function(data) {
				if(data.success){
					$.messager.progress('close');
					$.messager.alert('提示', '提交成功！', 'info', function() {
						/* parent.$('#dlg').dialog('close');
						parent.gotoSearch($('#easyui-treegrid')); */
						exitToList();
					});
					//window.location.href = "vchannel_programs.jsp";
				}else{
					$.messager.progress('close');
					$.messager.alert('提示', data.result, 'info', function() {
						/* parent.$('#dlg').dialog('close');
						parent.gotoSearch($('#easyui-treegrid')); */
						exitToList();
					});
				}
				
			},
			error:function(){
				$.messager.progress('close');
				$.messager.alert('提示', '提交失败！', 'info', function() {
					/* parent.$('#dlg').dialog('close');
					parent.gotoSearch($('#easyui-treegrid')); */
					//exitToList();
				});
				
			}
		});
 	}
	/**
	 * 素材选择
	 */
	function showMatrialListPage(){
		openDialog($('#dlg'),'vchannel_content_list.jsp?vchannelFlag=vchannel&type=1');
	}
	var sumTime=0;
	var serial_number = 0;
	/* 当关闭dialog的时候把选取的内容信息添加到table中  */
	function dialog_close(){
		$.ajax({
			url:"../../content/select_content.do?f_cc_id="+f_cc_id,
			success:function(data) {
				data = JSON.parse(data);
				var f_cc_id = data.f_cc_id;
				var f_cc_name = data.f_cc_name;
				var f_cc_duration = data.f_cc_duration;
				var f_cc_code = data.f_cc_code;
				var str = '';
				str += '<tr id="'+f_cc_id+'" class="virtual_channel_materials">';
				//str += '<td align="center">'+serial_number+'</td>';
				//str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_type"  value="'+f_vcm_type+'">';
				str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_viewIndex" class="viewindex" value="'+serial_number+'">';
				str += '<input type="hidden" id="dur_val_'+serial_number+'" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_duration" value="'+f_cc_duration+'">';
				str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_materialUrl" value="'+f_cc_code+'">';
				str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_materialName" value="'+f_cc_name+'">';
				str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_contentid" value="'+f_cc_id+'">';
				str += '<td align="center" class="f_vcm_materialName">'+f_cc_name+'</td>';
				if(f_cc_duration== 0||f_cc_duration==undefined){
					str += '<td align="center"><input id="val_'+serial_number+'" class="f_vcm_durationzb" name="dur" value="0" size="6" onchange="changeDur(this.id)" type="text">&nbsp;</td>';
				}else{
					str += '<td align="center" name="f_cc_duration" class="f_vcm_duration">'+f_cc_duration+'</td>';
				}
				str += '<td align="center" class="f_vcm_materialUrl">'+f_cc_code+'</td>';
				str += '<td align="center">';
				//str += '<a href="javascript:moveUp('+f_cc_id+',0,0,-1)">上移</a>';
				str += '<span class="operation" onClick="moveUp(this)">上移</span>';
				str += '&nbsp;&nbsp;&nbsp;&nbsp;<span class="operation" onClick="moveDown(this)">下移</a></span>';
				str += '&nbsp;&nbsp;&nbsp;&nbsp;<span class="operation" onClick="removeTr(this)">删除</a></span>';
				str += '</td></tr>';
				$('#carousel').append(str);
				//trOperation();
				serial_number++;
				/* if(f_cc_duration==''||f_cc_duration=="null"||f_cc_duration==null) f_cc_duration=0;
				sumTime+=parseInt(f_cc_duration);
				showTime(sumTime); */
				getSumtime();
			}
		});
		$('#dlg').dialog('close');
		return false;
	}
	function showTime(sumTime){
		$('#sumTime').empty();
		$('#sumTime').append('<font  color="#FF0000">(节目总时长：'+sumTime+'秒)&nbsp; </font> 提示：开始、结束时间格式：<font color="#FF0000">08:09:10</font>');
	}
	
	function changeDur(id){
		var dur = $("#"+id).val();
		/* var dur1 = $("#dur_"+id).val();
		if(dur1==''||dur1=="null"||dur1==null||dur1=="undefined"){
			dur1=0;
		} */
		//sumTime+=(parseInt(dur)-parseInt(dur1));
		$("#dur_"+id).val(dur);
		//showTime(sumTime);
		getSumtime();
	}
	/* 向上移动 */
	function moveUp(obj) {
		var current = $(obj).parent().parent();
		var prev = current.prev();
		if(prev.hasClass('title')){
			return false;
		}
		if (current.index() > 1) {
			var prev_index = $(prev).find('.viewindex').val();
			var curr_index = $(current).find('.viewindex').val();
			$(current).find('.viewindex').val(prev_index);
			$(prev).find('.viewindex').val(curr_index);
			
			$(current).find("input").each(function(){
				var $input = $(this);
				$input.attr("name", $input.attr("name").replace(/\[[0-9]\]/, "[" + prev_index + "]"));
			});
			
			$(prev).find("input").each(function(){
				var $input = $(this);
				$input.attr("name", $input.attr("name").replace(/\[[0-9]\]/, "[" + curr_index + "]"));
			});
			
			current.insertBefore(prev);
		}
	}
	
	/* 向下移动 */
	function moveDown(obj) {
		var current = $(obj).parent().parent();
		var next = current.next();
		if (next) {
			var curr_index = $(current).find('.viewindex').val();
			var next_index = $(next).find('.viewindex').val();
			$(current).find('.viewindex').val(next_index);
			$(next).find('.viewindex').val(curr_index);
			
			$(current).find("input").each(function(){
				var $input = $(this);
				$input.attr("name", $input.attr("name").replace(/\[[0-9]\]/, "[" + next_index + "]"));
			});
			
			$(next).find("input").each(function(){
				var $input = $(this);
				$input.attr("name", $input.attr("name").replace(/\[[0-9]\]/, "[" + curr_index + "]"));
			});
			
			current.insertAfter(next);
		}
	}
	/* 删除行  */
	function removeTr(obj){
		if(confirm("确定将素材从该时段中移除吗？")){
			var current = $(obj).parent().parent();
			current.remove();
			var $table = $(obj).parent().parent().parent();
		    var numSerials = 1;
		    var tmp = $table.find($('.viewindex'));
		    $('.viewindex').each(function(){
		    	//console.log('numSerials:'+numSerials);
		    	$(this).val(numSerials);
		    	numSerials++;
		    });
		}
	}
	
	/* 退出 */
	function exitToList() {
		var url  ='vchannel_programs.jsp';
		if(processType== 'interCutUpdate' || processType == 'interCutInsert'){
			url = "vchannel_program_edit.jsp?insertOrUpdate=update&f_vc_id="+turnid+"&f_vc_parentid="+turnpid+"&f_vc_customid="+turncid;
		}
		document.forms[0].action = url;
		document.forms[0].submit();
		//window.location.href = url;
	}
	
	
	function recalOfftime() {
		var dursObj = document.getElementsByName("dur");
		var durstr = "";
		for ( var k = 0; k < dursObj.length; k++) {
			var tmpV = dursObj[k].value;
			if (tmpV == "")
				tmpV = "0";
			if (durstr == "")
				durstr = tmpV;
			else
				durstr += "," + tmpV;
		}
		document.forms[0].durations.value = durstr;

		if (document.forms[0].f_vc_airTime.value == "") {
			alert("开始时间不能为空");
		}

		document.forms[0].action = "/makeplaylist/program.do?preform=selforadd&calTime=1";
		document.forms[0].submit();
	}
	
	/* 
	插播节目 
	无需查询原有的了，只需要把相应f_vc_id，f_vc_parentid，f_vc_customid传过去即可，
	但在传递参数的时候不能用跟修改同名的参数，不然会当做修改去查询然后渲染页面。
	
	*/
	function spots() {
		window.location.href = 'vchannel_program_edit.jsp?processType=interCutInsert&cbf_vc_id='+f_vc_id+'&cbf_vc_parentid='+f_vc_id+'&f_vc_customid='+f_vc_customid+'&turnid='+f_vc_id+'&turnpid='+f_vc_parentid+'&turncid='+f_vc_customid;;
	}
	
	
	function spots_modify(id) {
		document.forms[0].parentPeriodId.value = document.forms[0].periodId.value;
		document.forms[0].periodId.value = id;
		document.forms[0].ids.value = "";
		document.forms[0].f_vc_airTime.value = "";
		document.forms[0].offTime.value = "";
		document.forms[0].name.value = "";
		document.forms[0].action = "/makeplaylist/program.do?preform=selforadd";
		document.forms[0].submit();
	}
	

	
	/* 插播的时候时间选择 选择“开始时间”和“结束时间”用的 */
	function selectTime() {
		document.forms[0].f_vc_airTime.value = document.forms[0].timeSelect.value;
	}
	/* 
	修改的时候显示现在在播放的节目单列表 
	
	*/
	function viewMateral(id){
		$.ajax({
			url:"../../virtual_channel/select_channel_material.do?f_vc_id="+id,
			success:function(data) {
				data = JSON.parse(data);
				var f_vc_airTime = data.f_vc_airTime;
				var f_vc_offAirTime = data.f_vc_offAirTime;
				var vcmList = data.virtualChannelMaterialVos;//可得到播放时长，时间秒数
				var offAirTimes = f_vc_offAirTime.split(":");//结束时间
				var airTimes = f_vc_airTime.split(":");//开始时间
				var time = 0;//时长
				var str = '';
				var flag = 1;
				for(var i=0;i<vcmList.length;i++){
					time = vcmList[i].f_vcm_duration;
					if(getS(airTimes)+time>getS(offAirTimes)){//大于结束时间
						str += '<option value="'+getHMS(getS(airTimes))+'">';
						str += getHMS(getS(airTimes))+'~'+vcmList[i].f_vcm_materialName;
						str += '</option>';
						flag = 0;
					}else{
						str += '<option value="'+getHMS(getS(airTimes))+'">';
						str += getHMS(getS(airTimes))+'~'+vcmList[i].f_vcm_materialName;
						str += '</option>';
						airTimes = getHMS(getS(airTimes)+time).split(":");
						if(i == (vcmList.length-1)){
							i=-1;
						}
					}
					if(flag == 0){
						i = vcmList.length-1;
					}
				}
				$('#timeSelect').append(str);
			}
		});
	}

	//通过时间s得到hms
	function getHMS(times){
		 var time = parseInt(times);
		 var h = Math.floor(time / (60*60));
		 var m = Math.floor((time - 60*60*h) / 60);
		 var s = time - 60*60*h - m*60;
		 var hh = h+"";
		 var mm = m+"";
		 var ss = s+"";
		 if(h<10) hh = "0"+h;
		 if(m<10) mm = "0"+m;
		 if(s<10) ss = "0"+s;
		 return hh+":"+mm+":"+ss;
	}
	//通过时间hms得到s
	function getS(airTimes){
		 return parseInt(airTimes[0])*60*60+parseInt(airTimes[1])*60+parseInt(airTimes[2]);
	}
	

	/* 
	---在选择结束时间前，先判断此次编辑的时间段有没有节目在播放，如果有，提示重新选择时间段
	
	*/
	function selectOfftime_close(){
		$('#dlg1').dialog('close');
		if(!(offAirTime_== ""||offAirTime_==null||offAirTime_=="null"))
		selectOfftime();
	}
	function go_material_list(){
		openDialog($('#dlg1'),'vchannel_programs_material_list.jsp?offAirTime=choose&f_vc_id='+f_vc_id);
	}
	/* 在选择结束时间前，先判断此次编辑的时间段有没有节目在播放，如果有，提示重新选择时间段  */
	function selectOfftime() {
		var canSave = true;
		if(f_vc_parentid == '0'){//如果父id等于0，说明是第一次新增，不用判断选择的时间是否在有效期内
			
		}else{//存在节目列表，判断开始时间是否在有效期内
			//select_virtual_channel.do 此方法中的返回值可包含是否在有效期内
			var f_vc_airTime = $('#f_vc_airTime').val();
			$.ajax({
				url:"../../virtual_channel/channel_list.do",
				data: {f_vc_airTime:f_vc_airTime,f_vc_parentid:f_vc_parentid},
				dataType: "json",
				type: "post",
				success:function(data) {
					$('#f_vc_offAirTime').val(offAirTime_);
				}
			});
		}
		
		if (document.forms[0].name.value == "") {
			alert("节目名称不能为空");
			return;
		}
		if (document.forms[0].f_vc_name.value == "") {
			alert("开始时间不能为空");
			return;
		}

		if (!canSave) {
			alert("转播节目时长不能为0或空");
			return;
		}
		
		
	}
	
	/* 修改时查询素材详情 
		id : 节目唯一id
		flag : 
			normal  正常节目单修改
			interCut 插播节目单修改
		_f_vc_type : 类型，1，正常编辑节目 2，插播节目.在插播修改的时候要查询插播节目的详情，需要设置这个参数
	*/
	function select_update(id,flag,_f_vc_type){
		$.ajax({
			url:"../../virtual_channel/select_material.do",
			data:{f_vc_id:id,f_vc_type:_f_vc_type},	
			success:function(data) {
				data = JSON.parse(data);
				var f_cc_id = "";
				var f_cc_name = "";
				var f_cc_duration = "";
				var f_cc_code = "";
				var str = '';
				var MaterialList = data.virtualChannelMaterialVos;
				for(var i=0;i<MaterialList.length;i++){
					f_cc_id = MaterialList[i].f_vcm_contentid;
					f_cc_name = MaterialList[i].f_vcm_materialName;
					f_cc_duration = MaterialList[i].f_vcm_duration;
					f_cc_code = MaterialList[i].f_vcm_materialUrl;
					//serial_number=MaterialList[i].f_vcm_viewIndex;
					str += '<tr id="'+f_cc_id+'" class="virtual_channel_materials">';
					str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_viewIndex" class="viewindex" value="'+serial_number+'">';
					str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_duration" value="'+f_cc_duration+'">';
					str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_materialUrl" value="'+f_cc_code+'">';
					str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_materialName" value="'+f_cc_name+'">';
					str += '<input type="hidden" name="virtualChannelMaterialVos['+serial_number+'].f_vcm_contentid" value="'+f_cc_id+'">';
					str += '<td align="center" class="f_cc_name">'+f_cc_name+'</td>';
					if(f_cc_duration== 0){
						str += '<td align="center"><input class="f_cc_durationzb" name="dur" value="0" size="6" onkeypress="if (event.keyCode < 45 || event.keyCode > 57) {alert(\'请填入正确的数值\');event.returnValue = false;}" type="text">&nbsp;</td>';
					}else{
						str += '<td align="center" name="f_cc_duration" class="f_cc_duration">'+f_cc_duration+'</td>';
					}
					str += '<td align="center" class="f_cc_code">'+f_cc_code+'</td>';
					str += '<td align="center">';
					str += '<span class="operation" onClick="moveUp(this)">上移</span>';
					str += '&nbsp;&nbsp;&nbsp;&nbsp;<span class="operation" onClick="moveDown(this)">下移</a></span>';
					str += '&nbsp;&nbsp;&nbsp;&nbsp;<span class="operation" onClick="removeTr(this)">删除</a></span>';
					str += '</td></tr>';
					serial_number++;
				}
				$('#carousel').append(str);
				getSumtime();
				$("#f_vc_id").val(data.f_vc_id);
				$("#f_vc_name").val(data.f_vc_name);
				$("#f_vc_airTime").val(data.f_vc_airTime);
				$("#f_vc_offAirTime").val(data.f_vc_offAirTime);
				$("#f_vc_customid").val(data.f_vc_customid);
				$("#f_vc_parentid").val(data.f_vc_parentid);
				if(flag == 'normal'){
					//插播节目单列表
					var interCutVcVos = data.interCutvirtualChannelVos;
					//console.log('修改时插播节目单列表interCutVcVos:'+interCutVcVos);
					var interCutStr = '';
					for(var i=0;i<interCutVcVos.length;i++){
						var time_slot = interCutVcVos[i].f_vc_airTime + '~' + interCutVcVos[i].f_vc_offAirTime;//播放时段
						interCutStr += '<tr id="interCut_'+interCutVcVos[i].f_vc_id+'">';
						interCutStr += '<td align="center">'+interCutVcVos[i].f_vc_name+'</td>';
						interCutStr += '<td class="f_cc_duration"  align="center">'+time_slot+'</td>';
						interCutStr += '<td class="f_cc_code" align="center">素材列表</td>';
						interCutStr += '<td align="center">';
						interCutStr += '<span class="operation" onclick="updatefn('+interCutVcVos[i].f_vc_id+')">修改</span>&nbsp;&nbsp;&nbsp;&nbsp;';
						interCutStr += '<span class="operation" onclick="deletefn('+interCutVcVos[i].f_vc_id+')">删除</span>&nbsp;&nbsp;&nbsp;&nbsp;';
						interCutStr += '</td></tr>';
					}
					$('#cblist').append(interCutStr);
				}
			}
		});
		$('#dlg').dialog('close');
		return false;
	}
	
	/* 
		插播修改  
		processType : 插播修改
		
	*/
	function updatefn(id){
		window.location.href = 'vchannel_program_edit.jsp?processType=interCutUpdate&cbf_vc_id='+id+'&cbf_vc_parentid='+f_vc_id+'&f_vc_customid='+f_vc_customid+'&turnid='+f_vc_id+'&turnpid='+f_vc_parentid+'&turncid='+f_vc_customid;
	}
	/*  插播删除 */
	function deletefn(id){
		$.messager.confirm('确定删除内容','确定删除内容么?',function(r){
			if(r){
				app_ajax('../../virtual_channel/delete_channel.do?f_vc_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
				'',
				function(msg){
					if(msg.success) {
						alert("删除成功!");
						if (checkAjaxRequestValidity(msg)) {
							//gotoSearch($('#easyui-treegrid'));
							$('#interCut_'+id).remove();
						}
					} else {
						alert("删除异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
					window.location.reload();
				}
				);
			}
		});
	}

	
	/* 
		验证开播时间和停播时间是否有效，主要提示：本时间段已有其他节目，请调整节目播出时间
		08:09:10
		2018-08-01 
	*/
	function validateAirAndOffAir(_f_vc_airTime,_f_vc_offAirTime){
		var bo = true;
		var btmpAry = _f_vc_airTime.split(':');//开播时间
		var etmpAry = _f_vc_offAirTime.split(':');//停播时间
		var bdate = new Date(2018,1,1,btmpAry[0],btmpAry[1],btmpAry[2]);
		var edate = new Date(2018,1,1,etmpAry[0],etmpAry[1],etmpAry[2]);
		if(bdate.valueOf() > edate.valueOf()){//先验证用户输入时间是否有误
			//console.log('开播时间大于停播时间'+'bdate.valueOf():'+bdate.valueOf()+';edate.valueOf():'+edate.valueOf());
			bo = false;
			$.messager.alert('提示', '开播时间不能大于停播时间!');
		}
		var type = $('#f_vc_type').val();
		var btm = getS(btmpAry);
		var etm = getS(etmpAry);
		if(bo){
			$.ajax({
				url:"../../virtual_channel/channel_list.do",
				data: {f_vc_parentid:fvcid,f_vc_customid:f_vc_customid},
				dataType: "json",
				type: "post",
				success:function(data) {
					var vcList = data.rows;
					var flag = false;
					for(var i=0;i<vcList.length;i++){
						var airTime = vcList[i].f_vc_airTime.split(":");
						var offAirTime = vcList[i].f_vc_offAirTime.split(":");
						var air = getS(airTime);
						var offAir = getS(offAirTime);
						//判断这个时间段内是否存在节目
						if(insertOrUpdate == 'update'){//修改时，排除自己
							if(type == 1 && vcList[i].f_vc_id == f_vc_id){
								flag = true;
								continue;
							}
						}
						if( processType== 'interCutUpdate'){//插播
							if(type == 1 && vcList[i].f_vc_id == cbf_vc_parentid){//插播修改时，判断时间是否超出播放时段
								if(btm<air||btm>offAir){
									flag = false;
								}
							}else{
								if(type == 2 && vcList[i].f_vc_id == cbf_vc_id){//插播修改时排除自己
									flag = true;
									continue;
								}
							}
						}
						if(type == 2){//插播新增，判断时间是否超出播放时段
							if(vcList[i].f_vc_type == 1 && vcList[i].f_vc_id == cbf_vc_parentid){
								if(btm<air||btm>offAir){
									flag = false;
									break;
								}
							}
						}
						if(type == vcList[i].f_vc_type){//新增时判断时间是否有冲突
							if((btm <= air && air <= etm)||(btm <= offAir && offAir <= etm)||(btm <= air && offAir <= etm)||(air <= btm && etm <= offAir)){
								flag = false;
								break;
							}else{
								flag = true;
							}
						}else{
							flag = true;
						}
					}
					if(flag||vcList.length==0){
						saveData();
					}else{
						$.messager.alert('提示', '开播时间和停播时间选择异常,本时间段已有其他节目,请调整节目播出时间!');
					}
				}
			});
		}
	}

	function backPre() {
		history.go(-1);
	}
	
	function getSumtime(){
		sumTime = 0;
		var dursObj = document.getElementsByName("f_cc_duration");
		for ( var k = 0; k < dursObj.length; k++) {
			var tmpV = dursObj[k].innerHTML;
			sumTime += parseInt(tmpV);
		}
		var durs = document.getElementsByName("dur");
		for ( var i = 0; i < durs.length; i++) {
			var tmpV = durs[i].value;
			sumTime += parseInt(tmpV);
		}
		showTime(sumTime);
	}
</script>
<body>
	<form id="virtual_channel_form" name="form1" action="/makeplaylist/program.do?preform=add" method="post"  onsubmit="return checkAll();">
        <input type="hidden" id="f_vc_customid" name="f_vc_customid">
		<input type="hidden" id="f_vc_parentid" name="f_vc_parentid">
		<input type="hidden" id="f_vc_id" name="f_vc_id"  value="<%=f_vc_id%>">
		
		<input type="hidden" name="durations" value="">
		<!-- 类型，1，正常编辑节目 2，插播节目 -->
		<input id="f_vc_type" type="hidden" name="f_vc_type" value="1"/>
	
		<table width="99%" cellspacing="0" cellpadding="3" align="center" class="tablex">
			<tr>
				<td height="25" valign="middle" align="center" class="OperateTitle" colspan="4">节目编制</td>
			</tr>
			<tr>
				<td id="sumTime" colspan="3" style="text-align: left">
					
				</td>
				<td id="servertime" style="text-align: center; font-weight: bold"></td>
			</tr>
			<tr>
				<td style="text-align: left" colspan="3">时段名称:&nbsp;
					<input type="text" id="f_vc_name" name="f_vc_name" value="" size="15">
					<font color="#FF0000">*</font>&nbsp; 开始时间:&nbsp;
					<input type="text" id="f_vc_airTime" name="f_vc_airTime" value="" size="8">&nbsp;
					<font color="#FF0000">*</font>&nbsp; 
					<font id="timeSelectFont" size=2>时间选择 </font> 
					<select id="timeSelect" name="timeSelect" onchange="selectTime()">
						<option value="">手工填写
					</select> 
					<font id="offTimeFont" size=2> 结束时间:</font>&nbsp;
					<input type="text" id="f_vc_offAirTime" name="f_vc_offAirTime" value="" size="8">&nbsp; 
					<!-- <input type="button" name="reCal" class="button1" value="重新计算" onclick="recalOfftime()"> -->
					<input type="button" name="reCal" class="xbuton2" value="结束时间选择" onclick="go_material_list()">
				</td>
				<td>
				<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
				<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
				<input type="button" class="xbuton2" value="素材选择" onclick="showMatrialListPage()" />&nbsp; 
				<input type="button" name="cb" class="xbuton2" value="插播节目" onclick="spots()" />&nbsp;
				<input type="button" class="xbuton2" value="保存" onclick="save()" />&nbsp;
				<input type="button" class="xbuton2" value="退出" onclick="exitToList()" /></td>
			</tr>
		</table>
		<table id="carousel" width="99%" cellspacing="0" cellpadding="3" align="center" class="tablex">
			<tr>
				<th align="center" colSpan=4>轮播节目</th>
			</tr>
			<tr class="title">
				<th align="center" width="30%">素材名称</th>
				<th align="center" width="20%">时长(秒)</th>
				<th align="center" width="30%">路径</th>
				<th align="center" width="20%">操作</th>
			</tr>
		</table>
		<br>
		<!-- 插播节目列表 -->
		<table width="99%" id="cblist" cellspacing="0" cellpadding="3" align="center" class="tablex">
			<tr>
				<th align="center" colSpan=4>插播节目</th>
			</tr>
			<tr>
				<th align="center" width="30%">节目名称</th>
				<th align="center" width="20%">播放时段</th>
				<th align="center" width="30%">素材列表</th>
				<th align="center" width="20%">操作</th>
			</tr>
		</table>
		<!-- 节目素材选择列表 -->
		<div id="dlg" class="easyui-dialog"
			style="width: 950px; height: 600px; top:168px;padding-top: 0px;"
			data-options="title:'内容管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
			<iframe scrolling="auto" frameborder="0" style="width: 100%; height: 99%;"></iframe>
		</div>
		<!-- 结束时间选择列表 -->
		<div id="dlg1" class="easyui-dialog"
			style="width: 950px; height: 600px; top:168px;padding-top: 0px;"
			data-options="title:'内容管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
			<iframe scrolling="auto" frameborder="0" style="width: 100%; height: 99%;"></iframe>
		</div>
	</form>
<script language="javascript">
	$(function(){ 
		if(insertOrUpdate == 'insert'){//新增
			document.forms[0].cb.style.display = "none";//隐藏插播节目按钮
			document.getElementById("cblist").style.display = "none";//隐藏插播节目列表table

			document.getElementById("timeSelectFont").style.display = "none";//隐藏时间选择
			document.getElementById("timeSelect").style.display = "none";//隐藏时间选择
			document.forms[0].reCal.style.display = "none";//隐藏"结束时间"选择按钮
			//新增时分两种情况，一种是已经有个节目单，这个时候频道父id就是传过来的id。
			//第二种情况是第一次新增，这个时候可以没有父id
			$('#f_vc_parentid').val(f_vc_parentid);
			console.log('节目编制新增->f_vc_parentid:'+f_vc_parentid+';f_vc_id:'+f_vc_id+';f_vc_customid:'+f_vc_customid);
			$('#f_vc_customid').val(f_vc_customid);
			fvcid = f_vc_parentid;
		}else if(insertOrUpdate == 'update'){//修改
			//document.getElementById("offTimeFont").style.display = "none";//隐藏“结束时间”输入框
			//document.forms[0].reCal.style.display = "none";//隐藏"结束时间"选择按钮
			//document.forms[0].f_vc_offAirTime.style.display = "none";//隐藏“结束时间”输入框
			//只有插播的时候才显示
			document.getElementById("timeSelectFont").style.display = "none";//隐藏时间选择
			document.getElementById("timeSelect").style.display = "none";//隐藏时间选择
			$('#f_vc_parentid').val(f_vc_parentid);
			select_update(f_vc_id,'normal',1);
			fvcid = f_vc_parentid;
			console.log('节目编制修改->f_vc_parentid:'+f_vc_parentid+';f_vc_id:'+f_vc_id+';f_vc_customid:'+f_vc_customid);
		}else{//插播
			document.forms[0].cb.style.display = "none";//隐藏插播按钮
			document.getElementById("cblist").style.display = "none";//隐藏插播列表
			document.forms[0].f_vc_offAirTime.style.display = "none";//隐藏“结束时间”输入框
			document.getElementById("offTimeFont").style.display = "none";//隐藏“结束时间”输入框
			document.forms[0].reCal.style.display = "none";//隐藏"结束时间"选择按钮
			
			$('#f_vc_type').val(2);//把类型修改为插播
			$('#f_vc_parentid').val(cbf_vc_parentid);
			console.log('节目编制插播->cbf_vc_parentid:'+cbf_vc_parentid+';f_vc_id:'+f_vc_id+';f_vc_customid:'+f_vc_customid);
			if( processType== 'interCutUpdate'){//插播修改
				select_update(cbf_vc_id,'interCut',2);
				viewMateral(cbf_vc_parentid);//实例化节目单列表，供用户插播节目选择
				
			}else{//插播新增
				viewMateral(cbf_vc_id);//实例化节目单列表，供用户插播节目选择
			}
			
		}
		
		getSeverTime('servertime');
		
		
	});
	showTime(0);
</script>
</body>
</html>